package servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by v on 17-5-6.
 */
@WebServlet(name = "Forget",value = "/Forget")
public class Forget extends HttpServlet{
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username=req.getParameter("username");
        String question=req.getParameter("question");
        String answer=req.getParameter("answer");
        String password=Sql.getSql().findPassword(username,question,answer);

        //若返回的密码值为空，表示不通过这次查询
        if(password==null){
            resp.sendRedirect("/index.html");
        }else {
            resp.getWriter().write("你的密码为:"+password);
        }
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }
}
